package code;

/**
 * 
 * Holds the credit card information. 
 *
 */
public class DebitCard extends CardTypes
{
	private CheckingAccount fAccountConnectedTo;
	private double fLimit;
	
	/**
	 * Creates debit card with a limit and attaches the checking account 
	 * @param limit limit to attach on the account
	 * @param account the checking account associated with. 
	 */
	public DebitCard(double limit, CheckingAccount account)
	{
		fCardNumber = fNextCardNumber;
		fNextCardNumber++;
		fLimit = limit;
		fAccountConnectedTo = account;
	}
	
	/**
	 * Creates debit card
	 */
	public DebitCard()
	{
		this(0.0, null);
	}
	
	@Override
	public boolean pay(double amount)
	{
		if((fAccountConnectedTo.getBalance() - amount) < -fAccountConnectedTo.getDebitAmount())
		{
			fAccountConnectedTo.setBalance(fAccountConnectedTo.getBalance() - amount);
			return true;
		}
		else
		{
			return false;
		}
	}

}
